package com.example.esp8266;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.example.esp8266.databinding.EventItemBinding;

import org.eclipse.paho.client.mqttv3.MqttMessage;

public class EventAdapter extends ListAdapter<String, EventAdapter.ViewHolder> {

    private static final DiffUtil.ItemCallback<String> diffCallback = new DiffUtil.ItemCallback<String>() {
        @Override
        public boolean areItemsTheSame(@NonNull String oldItem, @NonNull String newItem) {
            return TextUtils.equals(oldItem,newItem);
        }

        @Override
        public boolean areContentsTheSame(@NonNull String oldItem, @NonNull String newItem) {
            return false;
        }
    };

    protected EventAdapter() {
        super(diffCallback);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(EventItemBinding.inflate(LayoutInflater.from(parent.getContext())));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String item = getItem(position);
        holder.content.setText(item);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private final LineNodeView lineNodeView;
        private final TextView content;

        public ViewHolder(@NonNull EventItemBinding binding) {
            super(binding.getRoot());
            lineNodeView = binding.line;
            content = binding.content;
        }
    }
}
